﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
using CrystalReportPrintLibrary;

namespace CrystalReportPrintService
{
    // 注意: 使用“重构”菜单上的“重命名”命令，可以同时更改代码、svc 和配置文件中的类名“Service1”。
    public class PrintService : IPrintService
    {

        public bool PrintCommandDefaultPrinter(string FileName, string Parameter, string UserName)
        {
            try
            {
                PrintClass Print = new PrintClass();
                IList<Parameter> Pars = new List<Parameter>();
                Parameter Par = new Parameter();
                Par.ParameterName = "DocEntry";
                Par.ParemeterValue = Parameter;
                Pars.Add(Par);
                string FilePath = System.Configuration.ConfigurationManager.AppSettings["FilePath"];
                FilePath += "\\" + FileName;
                Log.Logger.Writer(UserName + "  报表文件：" + FilePath + " ; 参数：" + Parameter);
                Print.CrystalReportPrint(OperateType.Print, FilePath, Pars);
                Log.Logger.Writer(UserName + "  sucessful");
                return true;
            }
            catch (Exception ex)
            {
                Log.Logger.Writer(ex);
                return false;
            }
        }
        public bool PrintCommand(string FileName, string Parameter, string PrinterName, string UserName)
        {
            try
            {
                PrintClass Print = new PrintClass();
                IList<Parameter> Pars = new List<Parameter>();
                Parameter Par = new Parameter();
                Par.ParameterName = "DocEntry";
                Par.ParemeterValue = Parameter;
                Pars.Add(Par);
                string FilePath = System.Configuration.ConfigurationManager.AppSettings["FilePath"];
                FilePath += "\\" + FileName;
                Log.Logger.Writer(UserName + "  报表文件：" + FilePath + " ; 参数：" + Parameter + " ； 打印机：" + PrinterName);
                Print.CrystalReportPrint(OperateType.Print, FilePath, Pars, PrinterName);
                Log.Logger.Writer(UserName + "  sucessful");
                return true;
            }
            catch (Exception ex)
            {
                Log.Logger.Writer(ex);
                return false;
            }
        }
    }
}
